package com.剑指offer;

import java.util.ArrayList;
import java.util.List;

/*
*
                输入一个链表的头节点，从尾到头反过来返回每个节点的值（用数组返回）。
                输入：head = [1,3,2]
                输出：[2,3,1]
* */
public class _3从尾到头打印链表
{
    public static void main(String[] args)
    {

    }

    public int[] reversePrint(ListNode head)
    {
        List<Integer> list = new ArrayList<>();
        while (head != null)
        {
            list.add(head.val);
            head = head.next;
        }
        if (list.size() < 1)
        {
            return new int[]{};
        }
        int a[] = new int[list.size()];
        for (int i = list.size() - 1; i >= 0; i--)
        {
            a[i] = list.get(list.size() - 1 - i);
        }
        return a;

    }


}
